﻿using BCDto.TMS.Agent.AgentAreaRecord;
using BCService.TMS.Agent.AgentAreaRecord;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.Agent
{
    /// <summary>
    /// 代理商区域记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class AgentAreaRecordController : ManagementBaseController
    {
        private readonly IAgentAreaRecordService agentAreaRecordService;

        public AgentAreaRecordController(IAgentAreaRecordService agentAreaRecordService)
        {
            this.agentAreaRecordService = agentAreaRecordService;
        }

        /// <summary>
        /// 添加代理商区域记录
        /// </summary>
        /// <param name="agentRecordId">代理商记录Id</param>
        /// <param name="requestDto">代理商区域添加模型信息</param>
        /// <response code="201">添加代理商区域记录</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加代理商区域记录")]
        [ProducesResponseType(typeof(AgentAreaRecordDto), 201)]
        public IActionResult Post([FromRoute(Name = "agent_record_id")] long agentRecordId,
            [FromBody] AgentAreaRecordRequestDto requestDto)
        {
            var result = this.agentAreaRecordService.Add(this.Admin, agentRecordId, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取代理商区域省市区三级联动树形列表
        /// </summary>
        /// <response code="200">获取代理商区域省市区三级联动树形列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<AgentAreaTreeDto>), 200)]
        public IActionResult Tree()
        {
            var result = this.agentAreaRecordService.GetAgentAreaTree(this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取已存在代理商的区域列表
        /// </summary>
        /// <response code="200">获取已存在代理商的区域列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<AgentAreaRecordDto>), 200)]
        public IActionResult AgentAreaExistsList()
        {
            var result = this.agentAreaRecordService.AgentAreaExistsList(this.Admin);
            return this.Ok(result);
        }

    }
}
